<?php
class FbtAction extends LoginAction
{
    /**
     * 执行楼层品牌类型显示
     * @author Ice iceinto@mallog.com.cn
     */
    public function floor ()
    {
        $id = getGet('id');
        $floor = $this->setFloorData($id);
        $market = $this->setMarketData($floor['mid']);
        //获取当前楼层品牌类型
        $map = array();
        $map['mid'] = $floor['mid'];
        $map['fid'] = $id;
        $fbtModel = M('FloorBrandType');
        $fbt = $fbtModel->where($map)->select();
        $this->assign('fbt', $fbt);
        $this->display();
    }
    /**
     * 执行楼层品牌类型添加
     * @param Int $id 商场ID
     * @author Ice iceinto@mallog.com.cn
     */
    public function add ()
    {
        $id = getGet('id');
        $floor = $this->setFloorData($id);
        $market = $this->setMarketData($floor['mid']);
        if (isPost()) {
            $fbtModel = D('FloorBrandType');
            $data = $this->getData();
            $status = $fbtModel->fbtAdd($data);
            if ($status['status'] == 1) {
                $this->successMessage('添加成功！');
            } else {
                $this->error($status['doc']);
            }
        }
        $this->display();
    }
    /**
     * 修改楼层操作
     * @author Ice iceinto@mallog.com.cn
     */
    public function edit ()
    {
        $id = (int) getGet('id');
        $rbt = $this->setFbtData($id);
        $floor = $this->setFloorData($rbt['fid']);
        $market = $this->setMarketData($floor['mid']);
        if (isPost()) {
            $fbtModel = D('FloorBrandType');
            $data = $this->getData();
            $data['id'] = $id;
            $status = $fbtModel->fbtUpdate($data);
            if ($status['status'] == 1) {
                $this->successMessage('修改成功！');
                $rbt = $this->setFbtData($id);
            } else {
                $this->error($status['doc']);
            }
        }
        $this->display();
    }
    /**
     * 设置
     * @param Int $id 商场楼层品牌类型ID
     * @author Ice iceinto@mallog.com.cn
     */
    public function setFbtData ($id)
    {
        $fbtModel = M('FloorBrandType');
        $map = array();
        $map['id'] = $id;
        $fbt = $fbtModel->where($map)->find();
        if ($fbt) {
            $this->assign('fbt', $fbt);
            return $fbt;
        } else {
            $this->error('数据传递有错误！');
        }
    }
    /**
     * 设置
     * @param Int $id 商场ID
     * @author Ice iceinto@mallog.com.cn
     */
    public function setMarketData ($id)
    {
        $MarketModel = M('market');
        $map = array();
        $map['id'] = $id;
        $market = $MarketModel->where($map)->find();
        if ($market) {
            $this->assign('market', $market);
            return $market;
        } else {
            $this->error('数据传递有错误！');
        }
    }
    /**
     * 设置和判断楼层参数
     * @param Int $id 楼层ID
     * @author Ice iceinto@mallog.com.cn
     */
    public function setFloorData ($id)
    {
        $FloorModel = M('Floor');
        $map = array();
        $map['id'] = $id;
        $floor = $FloorModel->where($map)->find();
        if ($floor) {
            $this->assign('floor', $floor);
            return $floor;
        } else {
            $this->error('数据传递有错误！');
        }
    }
    /**
     * 获取提交数据
     * @author Ice iceinto@mallog.com.cn
     */
    public function getData ()
    {
        $data = array();
        $data['mid'] = getPost('mid');
        $data['fid'] = getPost('fid');
        $data['name'] = getPost('tName');
        //判断必要性
        foreach ($data as $k => $d) {
            if (! $d) {
                $this->error($k . '不能为空！');
            }
        }
        return $data;
    }
}
?>